package com.itheima.reggie.config;

import com.github.xiaoymin.knife4j.spring.annotations.EnableKnife4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * Swagger配置类
 *
 * @Name : SwaggerConfig
 * @Author : WuQiang
 * @Description : Swagger配置类
 */

@Configuration
@EnableSwagger2
@EnableKnife4j
public class SwaggerConfig {

    /**
     * 接口文档的核心对象
     * @return
     */
    @Bean
    public Docket createRestApi() {
        // 文档类型
        return new Docket(DocumentationType.SWAGGER_2)   //swagger规范版本2.0
                .apiInfo(apiInfo())  //基本配置信息
                .select()  //过滤
                 //扫描 com.itheima.reggie.controller 下的Handler接口
                .apis(RequestHandlerSelectors.basePackage("com.itheima.reggie.web.controller"))
                //路径匹配
                .paths(PathSelectors.any())
                .build();
    }

    /**
     * 接口文档的声明信息
     * @return
     */
    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("瑞吉外卖")  //标题
                .version("1.0")   //版本
                .description("瑞吉外卖接口文档")   //描述
                .contact(new Contact("wq","http://www.wq.com", "wq@wq.cn"))
                .build();
    }

}
